package com.pubinfo.passbook.api.controller.rule;

import com.pubinfo.passbook.common.entity.TRuleFormula;
import com.pubinfo.passbook.common.model.dto.rule.RuleFormulaParam;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TRuleFormulaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("formula/manager")
@Api(tags = "计算公式")
public class TFormulaController {
  
  @Resource
  private TRuleFormulaService formulaService;

  @PostMapping("save")
  @ApiModelProperty("新增计算公式")
  public JsonResult<Boolean> saveFormula(@RequestBody TRuleFormula formula) {
    return JsonResult.success(formulaService.saveFormula(formula));
  }
  
  @DeleteMapping("remove")
  @ApiModelProperty("删除计算公式")
  public JsonResult<Boolean> removeFormula(String id) {
    return JsonResult.success(formulaService.removeById(id));
  }

  @PostMapping("update")
  @ApiModelProperty("更新计算公式")
  public JsonResult<String> updateFormula(@RequestBody TRuleFormula formula) {
    return formulaService.updateRuleFormula(formula);
  }
  
  @PostMapping("select")
  @ApiModelProperty("查询计算公式")
  public JsonResult<MyPage<TRuleFormula>> selectRuleFormula(@RequestBody RuleFormulaParam param) {
    return JsonResult.success(new MyPage(formulaService.selectRuleFormula(param)));
  }
}
